/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright (c) <2014-2018>, <Huawei Technologies Co., Ltd>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*----------------------------------------------------------------------------
 * Notice of Export Control Law
 * ===============================================
 * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
 * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
 * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
 * applicable export control laws and regulations.
 *---------------------------------------------------------------------------*/

/** @defgroup inet Inet
* @ingroup libc
*/


#ifndef _ARPA_INET_H_
#define _ARPA_INET_H_

#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */


/*
Func Name:  inet_addr
*/

/**
* @ingroup  inet
*
* @par Description:
* This function is used to convert the IPv4 address from string notation (number and dot format)
* to binary notation of network byte order.
*
* @param    cp    [IN]   Pointer to IPv4 address string.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval    #in_addr_t      On success, in unsigned int (32bit) format.
* @retval    #IPADDR_NONE    On failure.
*
* @par Dependency:
* <ul><li>inet.h</li></ul>
*
* @see inet_aton
*
* @since Huawei LiteOS V100R001C00
*/
in_addr_t inet_addr(const char *cp);

/*
Func Name:  inet_aton
*/

/**
* @ingroup  inet
*
* @par Description:
* This function is used to convert the IPv4 address from string notation (number and dot format)
* to binary notation of network byte order and stores it in the structure that addr points to.
*
* @param    cp    [IN]    Pointer to IPv4 address string.
* @param    inp   [OUT]   Generated binary notation of IPv4 address will be udpated here.
*
* @attention
* <ul>
* <li>This interface is same as inet_addr(). Only difference is that the generated binary notation
* of IPv4 address is updated in the input parameter "inp", instead of returning it.</li>
* </ul>
*
* @retval   #1   On success.
* @retval   #0   On failure.
*
* @par Dependency:
* <ul><li>inet.h</li></ul>
*
* @see inet_addr
*
* @since Huawei LiteOS V100R001C00
*/
int inet_aton(const char *cp, struct in_addr *inp);

/*
Func Name:  inet_ntoa
*/

/**
* @ingroup  inet
*
* @par Description:
* This function is used to convert the IPv4 address from binary notation (network byte order)
* to string notation (number and dot format).
*
* @param    in    [IN]    Pointer to binary notation of IPv4 address.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval   #char*          On success, returns pointer to string notation of IPv4 address.
* @retval   #NULL           On failure.
*
* @par Dependency:
* <ul><li>inet.h</li></ul>
*
* @see inet_ntop
*
* @since Huawei LiteOS V100R001C00
*/
char *inet_ntoa(struct in_addr in);

/*
Func Name:  inet_ntop
*/

/**
* @ingroup  inet
*
* @par Description:
* This  function is used to convert the network address structure src in the af address family into a character string.
* The resulting string is copied to the buffer pointed to by dst, which must be a non-null pointer.
* The caller specifies the number of bytes available in this buffer in the argument size.
*
* @param    af     [IN]    Address family.
* @param    src    [IN]    Pointer to IPv4 address string.
* @param    size   [IN]    Size of IPv4 address string.
* @param    dst    [OUT]   Result string of IPv4 address will be udpated here.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval   #char*          On success, returns pointer to string notation of IPv4 address.
* @retval   #NULL           On failure.
*
* @par Errors
* <ul>
* <li><b>EAFNOSUPPORT</b>: Address family not supported.</li>
* </ul>
*
* @par Dependency:
* <ul><li>inet.h</li></ul>
*
* @see inet_pton
*
* @since Huawei LiteOS V100R001C00
*/
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);

/*
Func Name:  inet_pton
*/

/**
* @ingroup  inet
*
* @par Description:
* This  function is used to convert the character string src into a network address
* structure in the af address family, then copies the network address structure to dst.
* The af argument must be AF_INET.
*
* @param    af    [IN]    Address family.
* @param    src   [IN]    Pointer to IPv4 address string.
* @param    dst   [OUT]   Result string of IPv4 address will be udpated here.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval    #1   On success, network address was successfully converted.
* @retval    #0   On failure, if src does not contain a character string representing a
*                 valid network address in the specified address family.
* @retval    #-1  On failure, if af does not contain a valid address family.
*
* @par Errors
* <ul>
* <li><b>EAFNOSUPPORT</b>: Address family not supported.</li>
* </ul>
*
* @par Dependency:
* <ul><li>inet.h</li></ul>
*
* @see inet_ntop
*
* @since Huawei LiteOS V100R001C00
*/
int inet_pton(int af, const char *src, void *dst);

#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */


#endif /* _ARPA_INET_H_ */
